<?php
/**
 * 
 * Internal URI requests interpreter, for env: schema 
 * 
 * @package WKernel
 *
 */
require_once 'WKernel/IRequest/Abstract.php';
class WK_IRequest_Env extends WK_IRequest_Abstract {
	protected function __run(){
		$result = new WK_Data_Map();
		if(preg_match('/^([a-zA-Z_]+:)?(.*)$/', $this->querystr, $matches)){
			$value = WK_App::getEnv($matches[2], $matches[1] ? trim($matches[1], ':') : 'app');
			if(!empty($value)) $result->newValue($matches[2], $value);
		}
		else {
			throw new WK_Error('Invalid URI "env:' . $this->querystr . '"', WERR_INVALID_INTERNAL_URI);
		}
		$this->result = $result;
	}	
}
WK_App::registerUriSchema('env', 'WK_IRequest_Env');